﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PureMVC.MVC.Views.Components;
using PureMVC.Patterns;
using ELooker.vlcWrapper;
using System.IO;
using ELooker.global;
using ELooker.utils;

namespace ELooker.MVC.Views.Mediators
{
   

    class MediatorMediaPanel:Mediator
    {
        public new const string NAME = "MediatorMediaPanel";
        private VLC vlc;
        private MediaPanel mediaPanel;

        public MediatorMediaPanel(MediaPanel viewComponent)
            : base(NAME, viewComponent)
        {
            mediaPanel = (MediaPanel)ViewComponent;
            initEntity();
            initEvents();
            
        }

        public override IList<string> ListNotificationInterests()
        {
            IList<string> list = new List<string>();
            list.Add(Notifications.MEDIATOR_MEDIA_PLAY);
            return list;
        }

        private void initEntity()
        {
            //本地保存路径
            String aviPath = Directory.GetCurrentDirectory() + "\\output\\output" + Entities.VLCs.Count + ".ts";

            //播放参数
            string[] argv = new string[] { "-I", "dumy", "--ignore-config", "--plugin-path=./plugins", "--sout=#duplicate{dst=display,dst=std{access=file,mux=ts,dst=" + aviPath + "}" };

            //vlc对象的创建
            vlc = new VLC(argv);
            Entities.VLCs.Add(vlc);
        }

        private void initEvents()
        {
            mediaPanel.onPlay += new EventHandler(mediaPanel_onPlay);
        }

        private void mediaPanel_onPlay(object sender, EventArgs e)
        {
            //要播放的文件的uri
            string uri = mediaPanel.TextBox1.Text;        //"C:\\Users\\Public\\Videos\\Sample Videos\\aaa.wmv";
            UtilsLogger.trace(uri);
            

            vlc.setRenderWindow((int)mediaPanel.Panel1.Handle);
            vlc.openMedia(uri);

            //

           // UtilsLogger.trace((int)libvlc_meta_t.libvlc_meta_URL);
           // VLC_API.libvlc_media_set_meta(vlc.LibvlcMediaPlayer, libvlc_meta_t.libvlc_meta_URL, Directory.GetCurrentDirectory() + "\\output\\output" + Entities.VLCs.Count + ".ts");
            VLC_API.libvlc_media_set_meta(vlc.MyPlayer, libvlc_meta_t.libvlc_meta_URL, "G:\\123.ts");
            String meta = VLC_API.libvlc_media_get_meta(vlc.MyPlayer, libvlc_meta_t.libvlc_meta_URL);
            //UtilsLogger.trace(meta);
            //VLC_API.libvlc_media_save_meta(vlc.MyPlayer);
        }
    }
}
